package com.bugreport.trackers.mantis128;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.unitils.UnitilsJUnit4;
import org.unitils.dbunit.annotation.DataSet;
import org.unitils.dbunit.annotation.ExpectedDataSet;
import org.unitils.spring.annotation.SpringApplicationContext;
import org.unitils.spring.annotation.SpringBeanByType;

import com.bugreport.model.Issue;
import com.bugreport.utils.BugReportException;

@DataSet
@SpringApplicationContext({ "com/bugreport/trackers/mantis128/spring-connector.xml",
		"com/bugreport/trackers/mantis128/spring-client.xml" })
public class Mantis128ConnectorTestCase extends UnitilsJUnit4 {

	// TODO verify correct throw exception on 404 error for example while calling remote service

	@SpringBeanByType
	private Mantis128TestConfiguration config;

	private Issue newIssue() {

		Issue issue = new Issue();
		issue.setTitle(config.getSummary());
		issue.setDescription(config.getDescription());
		issue.setPageHtmlContent(config.getAttachmentFileContent());

		return issue;
	}

	@Test
	@ExpectedDataSet
	public void reportIssue() throws BugReportException {

		Issue issue = newIssue();
		String issueId = config.getConnector().reportIssue(issue);

		assertNotNull(issueId);
		assertTrue(Long.valueOf(issueId) > 0);
	}
}
